package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.ProgramBean;
import com.project.mapper.IProcessMapper;
import com.project.mapper.IProgramMapper;
import com.project.service.IProgramService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class ProgramServiceImpl implements IProgramService {
    @Autowired
    private IProgramMapper programMapper;
    @Autowired
    private IProcessMapper processMapper;

    @Override
    public void add(ProgramBean program) {
        programMapper.add(program);
    }

    @Override
    public ProgramBean findById(int id) {
        return programMapper.findById(id);
    }

    @Override
    public List<ProgramBean> findNoFinish() {
        return programMapper.findNoFinish();
    }

    @Override
    public PageInfo<ProgramBean> findByItem(int pageNO, String name, String status, String orderItem) {
        PageHelper.startPage(pageNO,3);
        PageInfo<ProgramBean> info = PageInfo.of(programMapper.findByItem(name,status,orderItem));
        return info;
    }

    @Override
    public void finishProgram(int proId) {
        programMapper.finishProgram(proId);
        programMapper.updateProcess(proId, LocalDate.now().toString());
    }
}
